package com.lytoyo.neihanduanzi.utils;

import java.security.SecureRandom;
import java.util.Random;

/**
 * 验证码生成工具类
 * 采用SecureRandom真随机数
 */
public class VerCodeGenerateUtil {
    private static final String DIGITALALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final Random RANDOM = new SecureRandom();

    /**
     * 生成随机验证码
     * @return 返回四位验证码
     */
    public static String getVerCode(){
        char[] nonceChars = new char[6];
        for (int i = 0;i < nonceChars.length;++i){
            nonceChars[i] = DIGITALALPHABET.charAt(RANDOM.nextInt(DIGITALALPHABET.length()));
        }
        return new String(nonceChars);
    }
}
